package com.jimge.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jimge.mapper.ArticleMapper;
import com.jimge.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Calendar;
import java.util.List;

@Controller
public class ArticleController {

    @Autowired
    private ArticleMapper articleMapper;

    @RequestMapping("/toIndex")
    public String toIndex(Model model) {
        // 第一个参数：当前页   第二个参数：每页显示条数
        Page<Article> page = new Page<>(2, 2);
        IPage<Article> articleIPage = articleMapper.selectPage(page, null);
        System.out.println("articleIPage=="+articleIPage.getRecords());
        List<Article> articles = articleMapper.selectList(null);
        model.addAttribute("page",articleIPage);
//        model.addAttribute("currentYear", Calendar.getInstance().get(Calendar.YEAR));
        return "client/index";
    }

}
